package zy.blue7.common.vaildate.custom.config;


import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.validation.SmartValidator;
import zy.blue7.common.vaildate.custom.CommonSmartValidator;
import zy.blue7.common.vaildate.custom.rules.RuleInterface;
import zy.blue7.common.vaildate.custom.rules.impl.NameNotNullRuleInterfaceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @author blue7
 * @version 1.0
 * @date 2021/11/22 11:23
 * 一个入参对象可以有多个校验逻辑，则需要实现多个 RuleInterface接口
 */
@Component
public class RuleConfig {

    @Bean("zy01")
    public RuleInterface rule1() {

        return new NameNotNullRuleInterfaceImpl<>("7777");
    }


    @Bean("rule1")
    public SmartValidator aa(@Qualifier("zy01") RuleInterface rule1) {

        List<RuleInterface> list = new ArrayList<>();
        list.add(rule1);
        return new CommonSmartValidator(list);
    }
}
